# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
require 'zip/zipfilesystem'

    def upload_file
      file_data = params[:Filedata]
      file_name = params[:Filename].to_s
      file_path = params[:folder].to_s
      File.open(file_path + "/" + file_name, "wb") { |new_file| new_file.write(file_data.read) }
      render(:xml => "<success/>")
    end

    def download_zip
      files_array = params[:files].split(',')
      file_path = params[:folder]
      
      if(File.exist?("myDownloads.zip")) 
	File.delete("myDownloads.zip") 
      end
      
      Zip::ZipFile.open("myDownloads.zip", Zip::ZipFile::CREATE) {
        |zipfile|
        files_array.each{
	  |filename|
	  zipfile.file.open(filename, "w") {
	    |new_file|
	    File.open(file_path + "/" + filename, "rb"){ |file_content|  new_file.write(file_content.read)}
	  }
	}
      }
      send_file 'myDownloads.zip'
    end
	
end